
CC=gcc
AR=ar

BUILD_DIR=build
SRC_DIR=source
INC_DIR=include

TARGET=lib.a
SOURCE=$(foreach dir,$(SRC_DIR),$(wildcard $(dir)/*.c))
OBJS=$(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SOURCE)))
VPATH=$(SRC_DIR)

INCLUDE=$(foreach dir,$(INC_DIR),$(wildcard $(dir)/*h))
CFLAG=$(patsubst %,-I%,$(INC_DIR))

$(BUILD_DIR)/$(TARGET):$(OBJS)
	$(AR) rcs $@ $^

$(BUILD_DIR)/%.o:%.c $(INCLUDE) | create_build
	$(CC) -c $< -o $@ $(CFLAG)

.PHONY:clean create_build

clean:
	rm -r $(BUILD_DIR)

create_build:
	mkdir -p $(BUILD_DIR)
